home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BMUG Revelations
/
BMUG Revelations.toast
/
Utilities
/
Random
/
Commodore 64c
/
SOURCE
/
HardDrive.c
< prev
next >
Wrap
Text File
|
1994-02-24
|
4KB
|
146 lines
/*
Commodore 64 Emulator v0.1 Earle F. Philhower III
Copyright (C) 1993-4 (st916w9r@dunx1.ocs.drexel.edu)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "ProcessorTypes.h"
#include "MemoryCalls.h"
#include "Serial.h"
#include "HardDrive.h"
int PetConv(int c);
void PetConvString(Str32 c);
static byte ReadMac(unsigned char *data, int secondary);
static byte WriteMac(unsigned char data, int secondary);
static byte OpenMac(char *name, int length, int secondary);
static byte CloseMac(int secondary);
static byte PutByte(byte data, int secondary);
static byte GetByte(byte *data, int secondary);
enum { NOTINUSE=0, WRITE, READ };
typedef struct {
short fNum;
byte mode;
byte *buffer;
int bufOff;
long bufLen;
} FSInfo;
static FSInfo fsInfo[2];
static short dirID=0;
static byte PutByte(byte data, int secondary)
{
FSInfo *fs=&(fsInfo[secondary]);
if (fs->bufLen>=256) {
if (FSWrite(fs->fNum, &(fs->bufLen), fs->buffer)!=noErr) return kSerialError;
fs->bufLen=0; }
fs->buffer[fs->bufLen++]=data;
return kSerialOK;
}
static byte GetByte(byte *data, int secondary)
{
FSInfo *fs=&(fsInfo[secondary]);
if (fs->bufOff>=fs->bufLen) {
fs->bufLen=256;
FSRead(fs->fNum, &(fs->bufLen), fs->buffer);
if (fs->bufLen==0) return kSerialEOF;
fs->bufOff=0;}
*data=fs->buffer[fs->bufOff++];
return kSerialOK;
}
void HardInitialize(void)
{
fsInfo[0].buffer=GetMemory(256);
fsInfo[1].buffer=GetMemory(256);
fsInfo[0].mode=fsInfo[1].mode=NOTINUSE;
AddSerialDevice(9, ReadMac, WriteMac, OpenMac, CloseMac, NULL);
}
int PetConv(int c)
{
switch (c&0xe0) {
case 0x40:
case 0x60: return (c^0x20); }
return (c);
}
void PetConvString(Str32 c)
{
int i;
for (i=1; i<c[0]+1; i++) c[i]=PetConv(c[i]);
}
static byte WriteMac(unsigned char data, int secondary)
{
if (fsInfo[secondary].mode!=WRITE) return kFloppyError;
return PutByte(data, secondary);
}
static byte ReadMac(unsigned char *data, int secondary)
{
if (fsInfo[secondary].mode!=READ) return kFloppyError;
return GetByte(data, secondary);
}
static byte OpenMac(char *name, int length, int secondary)
{
Str32 tmp;
if (fsInfo[secondary].mode!=NOTINUSE) return kFloppyError;
if ((secondary<0)||(secondary>=2)) return kFloppyError;
BlockMove(name, tmp+1, length);
tmp[0]=length;
PetConvString(tmp);
if ((fsInfo[secondary].mode=(secondary==1?WRITE:READ))==WRITE)
Create(tmp, dirID, 'C64E', 'TEXT');
if (FSOpen(tmp, dirID, &(fsInfo[secondary].fNum))!=noErr) return kFloppyError;
fsInfo[secondary].bufLen=fsInfo[secondary].bufOff=0;
return kSerialOK;
}
static byte CloseMac(int secondary)
{
switch(fsInfo[secondary].mode) {
case WRITE:
if (fsInfo[secondary].bufLen>0)
FSWrite(fsInfo[secondary].fNum, &fsInfo[secondary].bufLen,
fsInfo[secondary].buffer);
case READ: FSClose(fsInfo[secondary].fNum); return kSerialOK;
default: return kSerialError; }
}
void HardChangeDirectory(void)
{
/*
Str255 str;
StandardFileReply sfReply;
Point pt={60,60};
StandardGetFolder(pt, "\pSelect New Directory For Drive 9:", &sfReply);
if (sfReply.sfGood==false) return;
dirID=sfReply.sfFile.parID;
NumToString(dirID, str);
DebugStr(str);
*/
}